//
//  main.c
//  杨氏矩阵数据查找
//
//  Created by 卜绎皓 on 2022/3/15.
//

#include<stdio.h>
#include<stdlib.h>
#define MAX_COL 3
#define MAX_ROW 3
int main(){
    int arr[MAX_ROW][MAX_COL]={
        {1,2,3},
        {5,8,9},
        {11,12,13},
    };
    int num;
    scanf("%d",&num);
    int ture = 0;
    int i = 0;
    int j = MAX_COL -1;
    while(1){
        if(num == arr[i][j]){
            ture = 1;
            break;
        }else if(num > arr[i][j]){
            i = i+1;
            if(i == MAX_ROW){
                break;
            }
        }else if(num < arr[i][j]){
            j = j - 1;
            if(j == -1){
                break;
            }
        }
    }
    if(ture == 1){
        printf("%d在矩阵中",num);
    }else{
        printf("%d不在矩阵中",num);
    }
    system("pause");
    return 0;
}

